package com.home.demo.controller;

import com.home.demo.common.R;
import com.home.demo.entity.MenuEntity;
import com.home.demo.entity.vo.menu.MenuTreeVO;
import com.home.demo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 
 * 菜单Controller
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 菜单查询
     */
    @GetMapping("getMenuTree")
    public R getMenuTree(){
        List<MenuTreeVO> menuTreeVO = menuService.getMenuTree();
        return R.ok().put("data",menuTreeVO);
    }




    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		MenuEntity menu = menuService.getById(id);

        return R.ok().put("data", menu);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody MenuEntity menu){
		menuService.saveInfo(menu);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody MenuEntity menu){
		menuService.updateById(menu);

        return R.ok();
    }

    /**
     * 删除菜单的时候 删除与角色的关联 还要删除关联的下级菜单
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id){
		menuService.removeByIdsInfo(id);

        return R.ok();
    }

}
